Add a Web API Data Source

  • The ability to use Web APIs within Digitise Apps is currently in preview. For more information, please contact your System Administrator or view the Connect section within the separate Hub Online Help. If you experience any problems using Web API Data Sources within Digitise Apps, please contact NDL's Helpdesk.

 

To add a Web API operation as a Data Source:

  1. Either

    • Right-click in the Data Sources Pane and then choose New Data Source → Web APIs (PREVIEW)

      or

    • From the Project group on the Ribbon's Home tab, choose New Data Source → Web APIs (PREVIEW).

  2. If the following error message appears:

    Picture showing the error message which will be displayed if you attempt to create a new Web API Data Source when the Connect Wizard Extension software is not installed.

    this means that the required Connect Wizard Extension software hasn't been installed on your development machine. You will need to install this software and then try again. For details of how to obtain and install the software, see Perform a New Install, Upgrade an Existing Version of Digitise Apps or Upgrade MX to Digitise Apps.

  3. If the Connect Wizard Extension software is installed, the Connect Services dialog box will be displayed, showing the Import Web APIs page:

    Picture showing the Import Web APIs Dialog Box.

    The Server URL provides details of how to connect to the Connect service which holds details about the Web API operation definitions you want to import into your Digitise Apps Project. The Connect service runs under a Hub agent, part of NDL's Hub product, and the address you enter here is the IP Address or machine name of the machine running the relevant Hub agent together with the port number assigned to Connect on that machine, in the format:

    <URL>:<port number>

    Whoever set up Hub and Connect should give you the required details to enter here, but, if you have access to Hub's Hub Manager software, you can find the appropriate machine name from within the Hub Manager Agents Screen, as shown below:

    Picture showing part of the Agents Screen within Hub Manager.

    In the picture above, Agent1 is the Hub agent running the Connect service. The Address field provides the machine name, in this case MyServer.MyComp.co.uk. Take the machine name and add the correct scheme (e.g., http) to the beginning and the port number to the end to convert it to the correct address format, e.g. http://MyServer.MyComp.co.uk:9000.

    Note that the port number included in the agent Address field needs to be replaced by the port number specified in the Connect Port field (without the comma), so using the picture above, the default agent's port number of 1111, would be replaced by 9000. See the Hub Manager Agents Screen topic within the separate Hub Online Help for more information about Hub agents.

    If you are running App Studio on the same machine as that running the Hub agent, then you can use the URL http://localhost:9000/ as shown in the Connect Services dialog box above, although you will need to substitute the correct port number, if Connect has been configured to use a different port than 9000.

     

    Back in the Connect Services dialog box, when you have finished, click on the Find Web APIs button to display the list of Web APIs available via the Connect service running on the specified server.

    Alternatively, to abandon importing a Web API, click the Cancel button or the Close button, Picture showing the Close Cross. , located in the top right-hand corner.

  4. If you choose the Find Web APIs button, a list of the available Web APIs will be displayed, arranged alphabetically:

    Picture Showing Find Web APIs option.

    Each Web API listed displays a description of the API and its contents, if one was entered when the Web API was imported into Connect. If the description is too long to fit, an ellipsis (‘…’) will appear at the end of the row. Hovering your mouse cursor over the Web API name box displays a tooltip, which contains the full description.

     

    You can return to the Import Web APIs page by clicking the Back button or cancel adding a Data Source by clicking the Cancel button or the dialog box's Close button, Picture showing the Close Cross. , in the upper, right-hand corner.

     

    Click on the Web API, whose operations you want to use in your app, in the list. You can click anywhere within the box containing the Web API's name.

  5. A list of the operations available in the selected Web API will be displayed:

    Picture showing Pet Store API Operations.

    The name of the Web API appears at the top of the screen, with a list of its available operations below it, in alphabetical order. Note that if an operation name contains any characters other than letters, underscores, hyphens, or numbers, these will be replaced with underscores. If the description for the Web API or any of its operations spans more than a single line, an ellipsis (‘…’) at the end of the description will indicate that more information is available. The additional information can be viewed by hovering your mouse cursor over the Web API or operation name box.

  6. To create a Data Source in your Project for an operation, click on the operation's name to select it. The operation name box will change to purple. The Import button will also turn a darker shade of purple to indicate that one or more operations have been selected.

    To import several operations at once, click on each of the required operations in the list in turn. To remove an operation from the selection, click the operation again. The item's background will turn from purple back to grey to show it has been deselected.

    When you have chosen the operations you wish to import, press the Import button.

  7. The imported operations will now be displayed as individual Data Sources in the Data Sources Pane.

    A new window will also appear in the Workspace for each new Data Source. Each window shows a, so-called, 'schema diagram' of the Data Source's tables. This is a sort of tree-view and looks something like this:

    Picture showing schema diagram showing tree structure of an imported Web API operation definition.

    At the top of the tree, the 'Data Source node' displays a name combining the names of the Web API and the operation. Branching off below this are sub-nodes representing the various tables containing columns matching the data items in the operation's definition. There will generally be two sets of tables, one set covering the parameters which can be included in the request message, where the tables will be named Request_*, e.g., Request_Pet in the image above, and the second covering the data items which can be returned in the response message, tables labelled Response_*, e.g., Response_Pet in the image above. There may be one or more tables in each set, depending upon the data requirements defined for the request and response messages, and if an operation doesn't return a response, there will only be request tables.

    Double-click on a table node to display the column fields within that table. Double-click on the caption bar at the top of the list to hide the fields again. Alternatively, you can toggle the display of the column fields by clicking on the Arrow symbol to the right of the table name or right-clicking on the table name and choosing Expand from the context menu.

  8. You now need to tell your Project which column fields from the request and response tables you want to use in your app. Each column name has a check box to the left of it. Select the check box for a column you want to include in your Project and the Data Mapping dialog box will appear:

    Picture showing Data Mapping dialog box mapping a column in a Web API Data Source.

    This dialog box allows you to specify a default value for this data item within your app and to specify whether this is a key field or not.

    Click OK to add the data item or Cancel if you don't want to add it. If you choose OK the data item will be displayed in the Data Sources Pane below the operation. The data item trees displayed in the Data Sources Pane illustrate the local database tables that will store the data on your mobile devices at runtime.

    You can map multiple data items within an individual table in one go. To do this, select the items in the standard manner by holding down the Ctrl or Shift keys whilst clicking on the required items (don't click on the check boxes) and then choose the Data Mappings button in the Data Source group on the Ribbon's Home tab. Choose Map Selected from the menu and the Data Mapping dialog box will be displayed with all your selected data items listed. If you want to set default values or specify key fields, select a data item from the list and then edit the options for that item. You can also change the relative positions of the items using the Move Up and Move Down buttons.

    The Data Mappings menu also allows you to delete the currently selected data items from your mapped list and to map or remove all data items in the current table. Alternatively, you can access these options by right-clicking on a table.

    You don't have to map all the required data items at once. You can come back and add or delete mappings at any time. However, you won't be able to link a data item to a Control until you have mapped it as described above.

    You can view and edit your data mappings by displaying the Data Sources Pane and double-clicking on the Data Source name, right-clicking on the name and choosing Open or, if displayed, clicking on the window or tab for the Data Source window in the Workspace.

    You must remember to include any required parameters from the request tables but optional parameters and response data items can be omitted if you don't need them in your app.

     

    When you expand a table node, you will see that the first column in the table is always a Primary Key ID column. This column is generated automatically and handled by your app but you must always include it in the Data Source.

    The name of this field will be based on the table name combined with '_NDLWSId'. For example, the following picture shows the earlier schema diagram with some of the tables expanded:

    Picture showing a Web API operation schema diagram in the App Studio Workspace.

    As mentioned earlier, the first part of each table name indicates whether its data items are part of the request or response. The Primary key field is named after the table, minus the 'Request_' or 'Response_' part, combined with '_NDLWSId'. For example, the first table is called Request_Pet and its Primary Key is called Pet_NDLWSId. The values in the Primary Key fields are generated automatically and, at runtime, each record in the table will be given a different value in order to uniquely identify each record in the table. You must include the Primary key fields in your Data Sources.

    Where the Request or Response consists of multiple tables, as in the diagram above, child tables will be linked to their parent tables by a Foreign Key field. This field will contain the Primary Key value from the corresponding parent record to link the two records together. For example, if you look at the second table in the diagram above, Request_Pet_photoUrls, you will see that the first column is its Primary Key field, Pet_photoUrls_NDLWSId, and the second column is named Pet_NDLWSId, which is the name of the Primary Key in the table above it. This field is used to link a record in the Request_Pet_photoUrls table to its corresponding record in the Request_Pet table. You must include these Foreign Key fields in your Data Source along with the Primary Key fields.

    • Primary Key fields are automatically populated when a new record is created. Foreign Key fields, however, are not and you will need to manually populate the field(s) with appropriate values either within a Script or by using an output mapped Control.
    • These Primary-Foreign Key relationships are used internally to keep track of related data tables on the local device and aren't forwarded to the Web API.
  9. Once you have added a Data Source, you may need to edit its Properties in order to get your app to work as required. You can display the Properties for any node or data item in the Data Sources Pane tree view, by clicking on the required node or data item. The Properties for the selected item will be displayed in the Properties Pane. Editable Properties are displayed in black. Those which can't be edited are displayed in grey. The main Properties are:

 

  • If, after publishing an app, you want to change some of the above Properties, such as the Connection String, Username, Password and Timeout values, for example to change between live and test data sources, you can't currently edit these Properties in App Manager as you can with other Data Sources. With Web API Data Sources, you will need to edit the app in App Studio, edit the Properties, republish the app and redeploy it to all relevant devices. You can, however, change the URL programmatically within your Scripts, if you need or want to.